﻿using EBFHelper.forms;
using EBFHelper.Nodes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;

namespace EBFHelper.EBFHelperUtil
{
    public class HelperModifyUtil
    {
        private static ContextMenuStrip contextMenuStrip;
        private static MyTreeNode m_tNode;
        private static  List<iNode> m_opStepXmlList;
        private static XmlDocument m_xmlDoc;

        public static void initContextMenuStrip()
        {
            contextMenuStrip = new ContextMenuStrip();
            ToolStripMenuItem detailInfo = new ToolStripMenuItem("详情");
            detailInfo.Click+=new EventHandler(detailInfo_Click);
            contextMenuStrip.Items.Add(detailInfo);

        }

        public static void showContextMenuStrip(TreeView treeView, int x, int y, MyTreeNode tNode, List<iNode> opStepXmlList)
        {
            m_tNode = tNode;
            m_opStepXmlList = opStepXmlList;
            if (null != contextMenuStrip)
                contextMenuStrip.Show(treeView,x,y);
        }

        public static void showContextMenuStrip(TreeView treeView, int x, int y, MyTreeNode tNode)
        {
            m_tNode = tNode;
            if (null != contextMenuStrip)
                contextMenuStrip.Show(treeView, x, y);
        }

        public static void showContextMenuStrip(ListBox listBox, int x, int y,XmlDocument xmlDoc)
        {
            m_xmlDoc = xmlDoc;
            if (null != contextMenuStrip)
                contextMenuStrip.Show(listBox, x, y);
        }

        private static void detailInfo_Click(Object sender,EventArgs e)
        {
            if (null != m_xmlDoc)
            {
                ActionXmlNodeDetailInfo aXNDI = new ActionXmlNodeDetailInfo(m_xmlDoc);
                aXNDI.Show();
                return;
            }

            if (null != m_opStepXmlList)
            {
                XmlNodeAtrributeInfo xNAI = new XmlNodeAtrributeInfo(m_tNode, m_opStepXmlList);
                xNAI.Show();
                m_opStepXmlList = null;
            }
            else
            {
                XmlNodeAtrributeInfo xNAI = new XmlNodeAtrributeInfo(m_tNode);
                xNAI.Show();
            }
        }
    }
}
